<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.6"/>
<title>qLibc: containers/qtreetbl.c File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">qLibc
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.6 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('qtreetbl_8c.html','');});
</script>
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">qtreetbl.c File Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>Tree Table container that implements "Left-Leaning Red-Black" BST algorithm.  
<a href="#details">More...</a></p>

<p><a href="qtreetbl_8c_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a598c177098cb87a5d2f9e898cc2cfeed"><td class="memItemLeft" align="right" valign="top">qtreetbl_t *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qtreetbl_8c.html#a598c177098cb87a5d2f9e898cc2cfeed">qtreetbl</a> (int options)</td></tr>
<tr class="memdesc:a598c177098cb87a5d2f9e898cc2cfeed"><td class="mdescLeft">&#160;</td><td class="mdescRight">Initialize a tree table.  <a href="#a598c177098cb87a5d2f9e898cc2cfeed">More...</a><br/></td></tr>
<tr class="separator:a598c177098cb87a5d2f9e898cc2cfeed"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af9e239f384bd9939c34361a45dd496a6"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qtreetbl_8c.html#af9e239f384bd9939c34361a45dd496a6">qtreetbl_set_compare</a> (qtreetbl_t *tbl, int(*cmp)(const void *name1, size_t namesize1, const void *name2, size_t namesize2))</td></tr>
<tr class="memdesc:af9e239f384bd9939c34361a45dd496a6"><td class="mdescLeft">&#160;</td><td class="mdescRight">qtreetbl-&gt;set_compare(): Set user comparator.  <a href="#af9e239f384bd9939c34361a45dd496a6">More...</a><br/></td></tr>
<tr class="separator:af9e239f384bd9939c34361a45dd496a6"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a49e05111c8541c7155e352fb618cf170"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qtreetbl_8c.html#a49e05111c8541c7155e352fb618cf170">qtreetbl_put</a> (qtreetbl_t *tbl, const char *name, const void *data, size_t datasize)</td></tr>
<tr class="memdesc:a49e05111c8541c7155e352fb618cf170"><td class="mdescLeft">&#160;</td><td class="mdescRight">qtreetbl-&gt;<a class="el" href="qhttpclient_8c.html#ae9ac3bd43c11509c0cbd8fb284bf13eb" title="qhttpclient-&gt;put(): Uploads a file to the remote host using PUT method. ">put()</a>: Put an object into this table with string type key.  <a href="#a49e05111c8541c7155e352fb618cf170">More...</a><br/></td></tr>
<tr class="separator:a49e05111c8541c7155e352fb618cf170"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a31e5908f6885033a58e354928e489b83"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qtreetbl_8c.html#a31e5908f6885033a58e354928e489b83">qtreetbl_putstr</a> (qtreetbl_t *tbl, const char *name, const char *str)</td></tr>
<tr class="memdesc:a31e5908f6885033a58e354928e489b83"><td class="mdescLeft">&#160;</td><td class="mdescRight">qtreetbl-&gt;putstr(): Put a string into this table.  <a href="#a31e5908f6885033a58e354928e489b83">More...</a><br/></td></tr>
<tr class="separator:a31e5908f6885033a58e354928e489b83"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ac475383244c35814d0950f0fa0c6414e"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qtreetbl_8c.html#ac475383244c35814d0950f0fa0c6414e">qtreetbl_putstrf</a> (qtreetbl_t *tbl, const char *name, const char *format,...)</td></tr>
<tr class="memdesc:ac475383244c35814d0950f0fa0c6414e"><td class="mdescLeft">&#160;</td><td class="mdescRight">qtreetbl-&gt;putstrf(): Put a formatted string into this table.  <a href="#ac475383244c35814d0950f0fa0c6414e">More...</a><br/></td></tr>
<tr class="separator:ac475383244c35814d0950f0fa0c6414e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ad2a7a784bf15be78fb7e72ab25940fe5"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qtreetbl_8c.html#ad2a7a784bf15be78fb7e72ab25940fe5">qtreetbl_put_by_obj</a> (qtreetbl_t *tbl, const void *name, size_t namesize, const void *data, size_t datasize)</td></tr>
<tr class="memdesc:ad2a7a784bf15be78fb7e72ab25940fe5"><td class="mdescLeft">&#160;</td><td class="mdescRight">qtreetbl-&gt;put_by_obj(): Put an object data into this table with an object name.  <a href="#ad2a7a784bf15be78fb7e72ab25940fe5">More...</a><br/></td></tr>
<tr class="separator:ad2a7a784bf15be78fb7e72ab25940fe5"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ab3232b711f0462533a066ecffb01a297"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qtreetbl_8c.html#ab3232b711f0462533a066ecffb01a297">qtreetbl_get</a> (qtreetbl_t *tbl, const char *name, size_t *datasize, bool newmem)</td></tr>
<tr class="memdesc:ab3232b711f0462533a066ecffb01a297"><td class="mdescLeft">&#160;</td><td class="mdescRight">qtreetbl-&gt;<a class="el" href="qhttpclient_8c.html#af16a3eb0912e8b5d4896466632d9c843" title="qhttpclient-&gt;get(): Downloads a file from the remote host using GET method. ">get()</a>: Get an object from this table.  <a href="#ab3232b711f0462533a066ecffb01a297">More...</a><br/></td></tr>
<tr class="separator:ab3232b711f0462533a066ecffb01a297"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a54b587a2c2d1a377cdc54c0e2e32d400"><td class="memItemLeft" align="right" valign="top">char *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qtreetbl_8c.html#a54b587a2c2d1a377cdc54c0e2e32d400">qtreetbl_getstr</a> (qtreetbl_t *tbl, const char *name, const bool newmem)</td></tr>
<tr class="memdesc:a54b587a2c2d1a377cdc54c0e2e32d400"><td class="mdescLeft">&#160;</td><td class="mdescRight">qtreetbl-&gt;getstr(): Finds an object and returns as string type.  <a href="#a54b587a2c2d1a377cdc54c0e2e32d400">More...</a><br/></td></tr>
<tr class="separator:a54b587a2c2d1a377cdc54c0e2e32d400"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a6ad04787f2efd3d4324b51fbb826fb38"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qtreetbl_8c.html#a6ad04787f2efd3d4324b51fbb826fb38">qtreetbl_get_by_obj</a> (qtreetbl_t *tbl, const char *name, size_t namesize, size_t *datasize, bool newmem)</td></tr>
<tr class="memdesc:a6ad04787f2efd3d4324b51fbb826fb38"><td class="mdescLeft">&#160;</td><td class="mdescRight">qtreetbl-&gt;get_by_obj(): Get an object from this table with an object name.  <a href="#a6ad04787f2efd3d4324b51fbb826fb38">More...</a><br/></td></tr>
<tr class="separator:a6ad04787f2efd3d4324b51fbb826fb38"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a3354408a36cb5d6fd724727dda04d1f3"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qtreetbl_8c.html#a3354408a36cb5d6fd724727dda04d1f3">qtreetbl_remove</a> (qtreetbl_t *tbl, const char *name)</td></tr>
<tr class="memdesc:a3354408a36cb5d6fd724727dda04d1f3"><td class="mdescLeft">&#160;</td><td class="mdescRight">qtreetbl-&gt;remove(): Remove an object from this table.  <a href="#a3354408a36cb5d6fd724727dda04d1f3">More...</a><br/></td></tr>
<tr class="separator:a3354408a36cb5d6fd724727dda04d1f3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a5b9465db5b03cb85a9b2d364b34d380f"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qtreetbl_8c.html#a5b9465db5b03cb85a9b2d364b34d380f">qtreetbl_remove_by_obj</a> (qtreetbl_t *tbl, const void *name, size_t namesize)</td></tr>
<tr class="memdesc:a5b9465db5b03cb85a9b2d364b34d380f"><td class="mdescLeft">&#160;</td><td class="mdescRight">qtreetbl-&gt;remove(): Remove an object from this table with an object name.  <a href="#a5b9465db5b03cb85a9b2d364b34d380f">More...</a><br/></td></tr>
<tr class="separator:a5b9465db5b03cb85a9b2d364b34d380f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aeb32bf5a193a0b7276cff302d3fcd090"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qtreetbl_8c.html#aeb32bf5a193a0b7276cff302d3fcd090">qtreetbl_getnext</a> (qtreetbl_t *tbl, qtreetbl_obj_t *obj, const bool newmem)</td></tr>
<tr class="memdesc:aeb32bf5a193a0b7276cff302d3fcd090"><td class="mdescLeft">&#160;</td><td class="mdescRight">qhashtbl-&gt;getnext(): Get next element.  <a href="#aeb32bf5a193a0b7276cff302d3fcd090">More...</a><br/></td></tr>
<tr class="separator:aeb32bf5a193a0b7276cff302d3fcd090"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a1f037a026ec877becd4f010226e00ea4"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qtreetbl_8c.html#a1f037a026ec877becd4f010226e00ea4">qtreetbl_find_min</a> (qtreetbl_t *tbl, size_t *namesize)</td></tr>
<tr class="memdesc:a1f037a026ec877becd4f010226e00ea4"><td class="mdescLeft">&#160;</td><td class="mdescRight">qtreetbl-&gt;find_min(): Find the name of very left object.  <a href="#a1f037a026ec877becd4f010226e00ea4">More...</a><br/></td></tr>
<tr class="separator:a1f037a026ec877becd4f010226e00ea4"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a1f70611ea89775d0ec580cc13eaa0069"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qtreetbl_8c.html#a1f70611ea89775d0ec580cc13eaa0069">qtreetbl_find_max</a> (qtreetbl_t *tbl, size_t *namesize)</td></tr>
<tr class="memdesc:a1f70611ea89775d0ec580cc13eaa0069"><td class="mdescLeft">&#160;</td><td class="mdescRight">qtreetbl-&gt;find_max(): Find the name of very right object.  <a href="#a1f70611ea89775d0ec580cc13eaa0069">More...</a><br/></td></tr>
<tr class="separator:a1f70611ea89775d0ec580cc13eaa0069"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aa2c4f3ac4623feb251fadabbdf734bdd"><td class="memItemLeft" align="right" valign="top">qtreetbl_obj_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qtreetbl_8c.html#aa2c4f3ac4623feb251fadabbdf734bdd">qtreetbl_find_nearest</a> (qtreetbl_t *tbl, const void *name, size_t namesize, bool newmem)</td></tr>
<tr class="memdesc:aa2c4f3ac4623feb251fadabbdf734bdd"><td class="mdescLeft">&#160;</td><td class="mdescRight">qtreetbl-&gt;find_nearest(): Find equal or nearest object.  <a href="#aa2c4f3ac4623feb251fadabbdf734bdd">More...</a><br/></td></tr>
<tr class="separator:aa2c4f3ac4623feb251fadabbdf734bdd"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a3537212a86616d50459eec229d94f8e4"><td class="memItemLeft" align="right" valign="top">size_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qtreetbl_8c.html#a3537212a86616d50459eec229d94f8e4">qtreetbl_size</a> (qtreetbl_t *tbl)</td></tr>
<tr class="memdesc:a3537212a86616d50459eec229d94f8e4"><td class="mdescLeft">&#160;</td><td class="mdescRight">qtreetbl-&gt;size(): Returns the number of keys in the table.  <a href="#a3537212a86616d50459eec229d94f8e4">More...</a><br/></td></tr>
<tr class="separator:a3537212a86616d50459eec229d94f8e4"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a7b324cf9e317a2623c5767b8a0183f72"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qtreetbl_8c.html#a7b324cf9e317a2623c5767b8a0183f72">qtreetbl_clear</a> (qtreetbl_t *tbl)</td></tr>
<tr class="memdesc:a7b324cf9e317a2623c5767b8a0183f72"><td class="mdescLeft">&#160;</td><td class="mdescRight">qtreetbl-&gt;clear(): Clears the table so that it contains no keys.  <a href="#a7b324cf9e317a2623c5767b8a0183f72">More...</a><br/></td></tr>
<tr class="separator:a7b324cf9e317a2623c5767b8a0183f72"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a5c8aa458bac0dc5e7dc0ab97c6f52dfd"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qtreetbl_8c.html#a5c8aa458bac0dc5e7dc0ab97c6f52dfd">qtreetbl_lock</a> (qtreetbl_t *tbl)</td></tr>
<tr class="memdesc:a5c8aa458bac0dc5e7dc0ab97c6f52dfd"><td class="mdescLeft">&#160;</td><td class="mdescRight">qtreetbl-&gt;lock(): Enter critical section.  <a href="#a5c8aa458bac0dc5e7dc0ab97c6f52dfd">More...</a><br/></td></tr>
<tr class="separator:a5c8aa458bac0dc5e7dc0ab97c6f52dfd"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a88a8e67f478390c6b25780fda3134a8d"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qtreetbl_8c.html#a88a8e67f478390c6b25780fda3134a8d">qtreetbl_unlock</a> (qtreetbl_t *tbl)</td></tr>
<tr class="memdesc:a88a8e67f478390c6b25780fda3134a8d"><td class="mdescLeft">&#160;</td><td class="mdescRight">qtreetbl-&gt;unlock(): Leave critical section.  <a href="#a88a8e67f478390c6b25780fda3134a8d">More...</a><br/></td></tr>
<tr class="separator:a88a8e67f478390c6b25780fda3134a8d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a2bac240b706b85273338a26fb986eee7"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qtreetbl_8c.html#a2bac240b706b85273338a26fb986eee7">qtreetbl_free</a> (qtreetbl_t *tbl)</td></tr>
<tr class="memdesc:a2bac240b706b85273338a26fb986eee7"><td class="mdescLeft">&#160;</td><td class="mdescRight">qtreetbl-&gt;free(): De-allocate the table  <a href="#a2bac240b706b85273338a26fb986eee7">More...</a><br/></td></tr>
<tr class="separator:a2bac240b706b85273338a26fb986eee7"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a61a3463749adb906e549d51f8a9c5a51"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a61a3463749adb906e549d51f8a9c5a51"></a>
int&#160;</td><td class="memItemRight" valign="bottom"><b>qtreetbl_byte_cmp</b> (const void *name1, size_t namesize1, const void *name2, size_t namesize2)</td></tr>
<tr class="separator:a61a3463749adb906e549d51f8a9c5a51"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a663dfe23addb8debd1c3da5e54d2c930"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="qtreetbl_8c.html#a663dfe23addb8debd1c3da5e54d2c930">qtreetbl_debug</a> (qtreetbl_t *tbl, FILE *out)</td></tr>
<tr class="memdesc:a663dfe23addb8debd1c3da5e54d2c930"><td class="mdescLeft">&#160;</td><td class="mdescRight">qtreetbl-&gt;debug(): Print hash table for debugging purpose  <a href="#a663dfe23addb8debd1c3da5e54d2c930">More...</a><br/></td></tr>
<tr class="separator:a663dfe23addb8debd1c3da5e54d2c930"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Tree Table container that implements "Left-Leaning Red-Black" BST algorithm. </p>
<p>qtreetbl implements a binary search tree that allows efficient in-order traversal with O(log n) search time.</p>
<p>The algorithm qtreetbl specifically implements is left-leaning red-black tree algorithm invented in 2008 by Robert Sedgewick. A left-leaning red–black tree is a type of self-balancing binary search tree and it is a variant of the red–black tree which was invented in 1972 by Rudolf Bayer.</p>
<p>References:</p>
<ul>
<li><a href="http://www.cs.princeton.edu/~rs/talks/LLRB/LLRB.pdf">http://www.cs.princeton.edu/~rs/talks/LLRB/LLRB.pdf</a></li>
<li><a href="http://www.cs.princeton.edu/~rs/talks/LLRB/RedBlack.pdf">http://www.cs.princeton.edu/~rs/talks/LLRB/RedBlack.pdf</a></li>
<li><a href="http://en.wikipedia.org/wiki/Left-leaning_red-black_tree">http://en.wikipedia.org/wiki/Left-leaning_red-black_tree</a></li>
</ul>
<p>Following example code will construct the data structure shown in below diagram. This example is quoted from the inventor's presentation slide p24-p25, <a href="http://www.cs.princeton.edu/~rs/talks/LLRB/RedBlack.pdf">http://www.cs.princeton.edu/~rs/talks/LLRB/RedBlack.pdf</a> and used in unit tests for verification purpose. </p>
<pre class="fragment">                           (E)
              ______________|______________
             /                             \
            (C)                           (R)
           /   \                         /   \
       (A,B)   (D)                   (I,N)   (S,X)

              &lt;2-3-4 Tree Data Structure&gt;

                            E
              ______________|______________
             /                             \
            C                               R
     _______|_______                 _______|_______
    /               \               /               \
   B                 D             N                 X
 //                              //                //
A*                              I*                S*

       Tree Info : tot=10, red=3, black=-7, root=E
Nodes A, I and S are nodes with RED upper link. Others are BLACK

       &lt;Left-Leaning Red-Black Tree Data Structure&gt;
</pre><p>Red-Black BST algorithm has been one of the famous BST algorithm especially for in-memory operation. It's been using in all around the computing area. I was very impressed about this variant, Left-Leaning version of Red-Black about how it improves the performance and reduces the overall complexity. Since it's relatively new algorithm, there's not many of practically functional working codes yet other than proof of concept kinds. Here's one of fully functional codes and I, Seungyoung Kim, would like to dedicate this code to the genius inventor Robert Sedgewick and to all the great qLibc users. Cheers!</p>
<p>Unique features:</p>
<ul>
<li>iterator. (have you ever seen iterator implementation in LLRB tree?)</li>
<li>find nearest key. (have you ever seen this as well? :)</li>
<li>iteration from given key.</li>
<li>find min/max key.</li>
</ul>
<div class="fragment"><div class="line">qtreetbl_t *tbl = <a class="code" href="qtreetbl_8c.html#a598c177098cb87a5d2f9e898cc2cfeed">qtreetbl</a>(QTREETBL_THREADSAFE);</div>
<div class="line"></div>
<div class="line">tbl-&gt;put(tbl, <span class="stringliteral">&quot;key&quot;</span>, <span class="stringliteral">&quot;DATA&quot;</span>, 4);          <span class="comment">// use put_by_obj() for binary keys.</span></div>
<div class="line"><span class="keywordtype">void</span> *data = tbl-&gt;get(tbl, <span class="stringliteral">&quot;key&quot;</span>, <span class="keyword">false</span>); <span class="comment">// use get_by_obj() for binary keys.</span></div>
<div class="line">tbl-&gt;remove(tbl, <span class="stringliteral">&quot;key&quot;</span>);                  <span class="comment">// use remove_by_key() for binary keys.</span></div>
<div class="line"></div>
<div class="line"><span class="comment">// iteration example</span></div>
<div class="line">tbl-&gt;lock(tbl);</div>
<div class="line">qtreetbl_obj_t obj = tbl-&gt;find_nearest(tbl, <span class="stringliteral">&quot;k&quot;</span>, 2, <span class="keyword">false</span>);</div>
<div class="line"><span class="keywordflow">while</span> (tbl-&gt;getnext(tbl, &amp;obj, <span class="keyword">false</span>) == <span class="keyword">true</span>) {</div>
<div class="line">  ...</div>
<div class="line">}</div>
<div class="line">tbl-&gt;unlock(tbl);</div>
<div class="line"></div>
<div class="line">tbl-&gt;set_compare(tbl, my_compare_func);</div>
<div class="line"><span class="keywordtype">size_t</span> num = tbl-&gt;size(tbl);</div>
<div class="line"><span class="keywordtype">void</span> *min = tbl-&gt;find_min(tbl, &amp;keysize);</div>
<div class="line">qtree_clean();</div>
<div class="line"></div>
<div class="line">tbl-&gt;free(tbl);</div>
</div><!-- fragment --> 
<p>Definition in file <a class="el" href="qtreetbl_8c_source.html">qtreetbl.c</a>.</p>
</div><h2 class="groupheader">Function Documentation</h2>
<a class="anchor" id="a598c177098cb87a5d2f9e898cc2cfeed"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">qtreetbl_t* qtreetbl </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>options</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Initialize a tree table. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">options</td><td>combination of initialization options.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>a pointer of malloced qtreetbl_t, otherwise returns NULL. </dd></dl>
<dl class="retval"><dt>Return values</dt><dd>
  <table class="retval">
    <tr><td class="paramname">errno</td><td>will be set in error condition.<ul>
<li>ENOMEM : Memory allocation failure.</li>
</ul>
</td></tr>
  </table>
  </dd>
</dl>
<div class="fragment"><div class="line">qtreetbl_t *tbl = <a class="code" href="qtreetbl_8c.html#a598c177098cb87a5d2f9e898cc2cfeed">qtreetbl</a>(0);</div>
</div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>Available options:<ul>
<li>QTREETBL_THREADSAFE - make it thread-safe. </li>
</ul>
</dd></dl>

<p>Definition at line <a class="el" href="qtreetbl_8c_source.html#l00171">171</a> of file <a class="el" href="qtreetbl_8c_source.html">qtreetbl.c</a>.</p>

</div>
</div>
<a class="anchor" id="af9e239f384bd9939c34361a45dd496a6"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void qtreetbl_set_compare </td>
          <td>(</td>
          <td class="paramtype">qtreetbl_t *&#160;</td>
          <td class="paramname"><em>tbl</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int(*)(const void *name1, size_t namesize1, const void *name2, size_t namesize2)&#160;</td>
          <td class="paramname"><em>cmp</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>qtreetbl-&gt;set_compare(): Set user comparator. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">tbl</td><td>qtreetbl_t container pointer. </td></tr>
    <tr><td class="paramname">cmp</td><td>a pointer to the user comparator function.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section note"><dt>Note</dt><dd>By default, qtreetbl uses byte comparator that works for both binary type key and string type key. Please refer qtreetbl_byte_cmp() for your idea to make your own comparator, </dd></dl>

<p>Definition at line <a class="el" href="qtreetbl_8c_source.html#l00240">240</a> of file <a class="el" href="qtreetbl_8c_source.html">qtreetbl.c</a>.</p>

</div>
</div>
<a class="anchor" id="a49e05111c8541c7155e352fb618cf170"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool qtreetbl_put </td>
          <td>(</td>
          <td class="paramtype">qtreetbl_t *&#160;</td>
          <td class="paramname"><em>tbl</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>name</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const void *&#160;</td>
          <td class="paramname"><em>data</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>datasize</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>qtreetbl-&gt;<a class="el" href="qhttpclient_8c.html#ae9ac3bd43c11509c0cbd8fb284bf13eb" title="qhttpclient-&gt;put(): Uploads a file to the remote host using PUT method. ">put()</a>: Put an object into this table with string type key. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">tbl</td><td>qtreetbl_t container pointer. </td></tr>
    <tr><td class="paramname">name</td><td>key name </td></tr>
    <tr><td class="paramname">data</td><td>data object </td></tr>
    <tr><td class="paramname">datasize</td><td>size of data object</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if successful, otherwise returns false </dd></dl>
<dl class="retval"><dt>Return values</dt><dd>
  <table class="retval">
    <tr><td class="paramname">errno</td><td>will be set in error condition.<ul>
<li>EINVAL : Invalid argument.</li>
<li>ENOMEM : Memory allocation failure. </li>
</ul>
</td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="qtreetbl_8c_source.html#l00260">260</a> of file <a class="el" href="qtreetbl_8c_source.html">qtreetbl.c</a>.</p>

</div>
</div>
<a class="anchor" id="a31e5908f6885033a58e354928e489b83"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool qtreetbl_putstr </td>
          <td>(</td>
          <td class="paramtype">qtreetbl_t *&#160;</td>
          <td class="paramname"><em>tbl</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>name</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>str</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>qtreetbl-&gt;putstr(): Put a string into this table. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">tbl</td><td>qtreetbl container pointer. </td></tr>
    <tr><td class="paramname">name</td><td>key name. </td></tr>
    <tr><td class="paramname">str</td><td>string data.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if successful, otherwise returns false. </dd></dl>
<dl class="retval"><dt>Return values</dt><dd>
  <table class="retval">
    <tr><td class="paramname">errno</td><td>will be set in error condition.<ul>
<li>EINVAL : Invalid argument.</li>
<li>ENOMEM : Memory allocation failure. </li>
</ul>
</td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="qtreetbl_8c_source.html#l00279">279</a> of file <a class="el" href="qtreetbl_8c_source.html">qtreetbl.c</a>.</p>

</div>
</div>
<a class="anchor" id="ac475383244c35814d0950f0fa0c6414e"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool qtreetbl_putstrf </td>
          <td>(</td>
          <td class="paramtype">qtreetbl_t *&#160;</td>
          <td class="paramname"><em>tbl</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>name</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>format</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname"><em>...</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>qtreetbl-&gt;putstrf(): Put a formatted string into this table. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">tbl</td><td>qtreetbl_t container pointer. </td></tr>
    <tr><td class="paramname">name</td><td>key name. </td></tr>
    <tr><td class="paramname">format</td><td>formatted string data.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if successful, otherwise returns false. </dd></dl>
<dl class="retval"><dt>Return values</dt><dd>
  <table class="retval">
    <tr><td class="paramname">errno</td><td>will be set in error condition.<ul>
<li>EINVAL : Invalid argument.</li>
<li>ENOMEM : Memory allocation failure. </li>
</ul>
</td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="qtreetbl_8c_source.html#l00297">297</a> of file <a class="el" href="qtreetbl_8c_source.html">qtreetbl.c</a>.</p>

</div>
</div>
<a class="anchor" id="ad2a7a784bf15be78fb7e72ab25940fe5"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool qtreetbl_put_by_obj </td>
          <td>(</td>
          <td class="paramtype">qtreetbl_t *&#160;</td>
          <td class="paramname"><em>tbl</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const void *&#160;</td>
          <td class="paramname"><em>name</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>namesize</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const void *&#160;</td>
          <td class="paramname"><em>data</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>datasize</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>qtreetbl-&gt;put_by_obj(): Put an object data into this table with an object name. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">tbl</td><td>qtreetbl_t container pointer. </td></tr>
    <tr><td class="paramname">name</td><td>key name </td></tr>
    <tr><td class="paramname">namesize</td><td>key size </td></tr>
    <tr><td class="paramname">data</td><td>data object </td></tr>
    <tr><td class="paramname">datasize</td><td>size of data object</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if successful, otherwise returns false </dd></dl>
<dl class="retval"><dt>Return values</dt><dd>
  <table class="retval">
    <tr><td class="paramname">errno</td><td>will be set in error condition.<ul>
<li>EINVAL : Invalid argument.</li>
<li>ENOMEM : Memory allocation failure.</li>
</ul>
</td></tr>
  </table>
  </dd>
</dl>
<dl class="section note"><dt>Note</dt><dd>This is the underlying put function which all other put methods use. </dd></dl>

<p>Definition at line <a class="el" href="qtreetbl_8c_source.html#l00328">328</a> of file <a class="el" href="qtreetbl_8c_source.html">qtreetbl.c</a>.</p>

</div>
</div>
<a class="anchor" id="ab3232b711f0462533a066ecffb01a297"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void* qtreetbl_get </td>
          <td>(</td>
          <td class="paramtype">qtreetbl_t *&#160;</td>
          <td class="paramname"><em>tbl</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>name</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t *&#160;</td>
          <td class="paramname"><em>datasize</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool&#160;</td>
          <td class="paramname"><em>newmem</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>qtreetbl-&gt;<a class="el" href="qhttpclient_8c.html#af16a3eb0912e8b5d4896466632d9c843" title="qhttpclient-&gt;get(): Downloads a file from the remote host using GET method. ">get()</a>: Get an object from this table. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">tbl</td><td>qtreetbl_t container pointer. </td></tr>
    <tr><td class="paramname">name</td><td>key name. </td></tr>
    <tr><td class="paramname">datasize</td><td>if not NULL, oject size will be stored. </td></tr>
    <tr><td class="paramname">newmem</td><td>whether or not to allocate memory for the data.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>a pointer of data if the key is found, otherwise returns NULL. </dd></dl>
<dl class="retval"><dt>Return values</dt><dd>
  <table class="retval">
    <tr><td class="paramname">errno</td><td>will be set in error condition.<ul>
<li>ENOENT : No such key found.</li>
<li>EINVAL : Invalid argument.</li>
<li>ENOMEM : Memory allocation failure.</li>
</ul>
</td></tr>
  </table>
  </dd>
</dl>
<div class="fragment"><div class="line">qtreetbl_t *tbl = <a class="code" href="qtreetbl_8c.html#a598c177098cb87a5d2f9e898cc2cfeed">qtreetbl</a>(0);</div>
<div class="line">(...codes...)</div>
<div class="line"></div>
<div class="line"><span class="comment">// with newmem flag unset</span></div>
<div class="line"><span class="keywordtype">size_t</span> size;</div>
<div class="line"><span class="keywordtype">void</span> *data = (<span class="keyword">struct </span>myobj*)tbl-&gt;get(tbl, <span class="stringliteral">&quot;key_name&quot;</span>, &amp;size, <span class="keyword">false</span>);</div>
<div class="line"></div>
<div class="line"><span class="comment">// with newmem flag set</span></div>
<div class="line"><span class="keywordtype">size_t</span> size;</div>
<div class="line"><span class="keywordtype">void</span> *data  = (<span class="keyword">struct </span>myobj*)tbl-&gt;get(tbl, <span class="stringliteral">&quot;key_name&quot;</span>, &amp;size, <span class="keyword">true</span>);</div>
<div class="line">free(data);</div>
</div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>If newmem flag is set, returned data will be malloced and should be deallocated by user. Otherwise returned pointer will point internal buffer directly and should not be de-allocated by user. In thread-safe mode, newmem flag must be set to true always. </dd></dl>

<p>Definition at line <a class="el" href="qtreetbl_8c_source.html#l00384">384</a> of file <a class="el" href="qtreetbl_8c_source.html">qtreetbl.c</a>.</p>

</div>
</div>
<a class="anchor" id="a54b587a2c2d1a377cdc54c0e2e32d400"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">char* qtreetbl_getstr </td>
          <td>(</td>
          <td class="paramtype">qtreetbl_t *&#160;</td>
          <td class="paramname"><em>tbl</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>name</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const bool&#160;</td>
          <td class="paramname"><em>newmem</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>qtreetbl-&gt;getstr(): Finds an object and returns as string type. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">tbl</td><td>qtreetbl_t container pointer. </td></tr>
    <tr><td class="paramname">name</td><td>key name </td></tr>
    <tr><td class="paramname">newmem</td><td>whether or not to allocate memory for the data.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>a pointer of data if the key is found, otherwise returns NULL. </dd></dl>
<dl class="retval"><dt>Return values</dt><dd>
  <table class="retval">
    <tr><td class="paramname">errno</td><td>will be set in error condition.<ul>
<li>ENOENT : No such key found.</li>
<li>EINVAL : Invalid argument.</li>
<li>ENOMEM : Memory allocation failure.</li>
</ul>
</td></tr>
  </table>
  </dd>
</dl>
<dl class="section note"><dt>Note</dt><dd>If newmem flag is set, returned data will be malloced and should be deallocated by user. Otherwise returned pointer will point internal buffer directly and should not be de-allocated by user. In thread-safe mode, newmem flag must be set to true always. </dd></dl>

<p>Definition at line <a class="el" href="qtreetbl_8c_source.html#l00410">410</a> of file <a class="el" href="qtreetbl_8c_source.html">qtreetbl.c</a>.</p>

</div>
</div>
<a class="anchor" id="a6ad04787f2efd3d4324b51fbb826fb38"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void* qtreetbl_get_by_obj </td>
          <td>(</td>
          <td class="paramtype">qtreetbl_t *&#160;</td>
          <td class="paramname"><em>tbl</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>name</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>namesize</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t *&#160;</td>
          <td class="paramname"><em>datasize</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool&#160;</td>
          <td class="paramname"><em>newmem</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>qtreetbl-&gt;get_by_obj(): Get an object from this table with an object name. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">tbl</td><td>qtreetbl_t container pointer. </td></tr>
    <tr><td class="paramname">name</td><td>key name </td></tr>
    <tr><td class="paramname">namesize</td><td>key size </td></tr>
    <tr><td class="paramname">datasize</td><td>if not NULL, oject size will be stored. </td></tr>
    <tr><td class="paramname">newmem</td><td>whether or not to allocate memory for the data.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>a pointer of data if the key is found, otherwise returns NULL. </dd></dl>
<dl class="retval"><dt>Return values</dt><dd>
  <table class="retval">
    <tr><td class="paramname">errno</td><td>will be set in error condition.<ul>
<li>ENOENT : No such key found.</li>
<li>EINVAL : Invalid argument.</li>
<li>ENOMEM : Memory allocation failure.</li>
</ul>
</td></tr>
  </table>
  </dd>
</dl>
<dl class="section note"><dt>Note</dt><dd>If newmem flag is set, returned data will be malloced and should be deallocated by user. Otherwise returned pointer will point internal buffer directly and should not be de-allocated by user. In thread-safe mode, newmem flag must be set to true always. </dd></dl>

<p>Definition at line <a class="el" href="qtreetbl_8c_source.html#l00437">437</a> of file <a class="el" href="qtreetbl_8c_source.html">qtreetbl.c</a>.</p>

</div>
</div>
<a class="anchor" id="a3354408a36cb5d6fd724727dda04d1f3"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool qtreetbl_remove </td>
          <td>(</td>
          <td class="paramtype">qtreetbl_t *&#160;</td>
          <td class="paramname"><em>tbl</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>name</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>qtreetbl-&gt;remove(): Remove an object from this table. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">tbl</td><td>qtreetbl_t container pointer. </td></tr>
    <tr><td class="paramname">name</td><td>key name</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if successful, otherwise(not found) returns false </dd></dl>
<dl class="retval"><dt>Return values</dt><dd>
  <table class="retval">
    <tr><td class="paramname">errno</td><td>will be set in error condition.<ul>
<li>ENOENT : No such key found.</li>
<li>EINVAL : Invalid argument. </li>
</ul>
</td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="qtreetbl_8c_source.html#l00468">468</a> of file <a class="el" href="qtreetbl_8c_source.html">qtreetbl.c</a>.</p>

</div>
</div>
<a class="anchor" id="a5b9465db5b03cb85a9b2d364b34d380f"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool qtreetbl_remove_by_obj </td>
          <td>(</td>
          <td class="paramtype">qtreetbl_t *&#160;</td>
          <td class="paramname"><em>tbl</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const void *&#160;</td>
          <td class="paramname"><em>name</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>namesize</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>qtreetbl-&gt;remove(): Remove an object from this table with an object name. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">tbl</td><td>qtreetbl_t container pointer. </td></tr>
    <tr><td class="paramname">name</td><td>key name </td></tr>
    <tr><td class="paramname">name</td><td>key size</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if successful, otherwise(not found) returns false </dd></dl>
<dl class="retval"><dt>Return values</dt><dd>
  <table class="retval">
    <tr><td class="paramname">errno</td><td>will be set in error condition.<ul>
<li>ENOENT : No such key found.</li>
<li>EINVAL : Invalid argument. </li>
</ul>
</td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="qtreetbl_8c_source.html#l00485">485</a> of file <a class="el" href="qtreetbl_8c_source.html">qtreetbl.c</a>.</p>

</div>
</div>
<a class="anchor" id="aeb32bf5a193a0b7276cff302d3fcd090"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool qtreetbl_getnext </td>
          <td>(</td>
          <td class="paramtype">qtreetbl_t *&#160;</td>
          <td class="paramname"><em>tbl</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">qtreetbl_obj_t *&#160;</td>
          <td class="paramname"><em>obj</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const bool&#160;</td>
          <td class="paramname"><em>newmem</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>qhashtbl-&gt;getnext(): Get next element. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">tbl</td><td>qhashtbl_t container pointer. </td></tr>
    <tr><td class="paramname">obj</td><td>found data will be stored in this object </td></tr>
    <tr><td class="paramname">newmem</td><td>whether or not to allocate memory for the data.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if found otherwise returns false </dd></dl>
<dl class="retval"><dt>Return values</dt><dd>
  <table class="retval">
    <tr><td class="paramname">errno</td><td>will be set in error condition.<ul>
<li>ENOENT : No next element.</li>
<li>EINVAL : Invalid argument.</li>
<li>ENOMEM : Memory allocation failure.</li>
</ul>
</td></tr>
  </table>
  </dd>
</dl>
<div class="fragment"><div class="line">[Iteration example from the beginning]</div>
<div class="line">qtreetbl_obj_t obj;</div>
<div class="line">memset((<span class="keywordtype">void</span>*)&amp;obj, 0, <span class="keyword">sizeof</span>(obj)); <span class="comment">// must be cleared before call</span></div>
<div class="line">tbl-&gt;lock(tbl);  <span class="comment">// lock it when thread condition is expected</span></div>
<div class="line"><span class="keywordflow">while</span>(tbl-&gt;getnext(tbl, &amp;obj, <span class="keyword">false</span>) == <span class="keyword">true</span>) {</div>
<div class="line">   <span class="comment">//</span></div>
<div class="line">   <span class="comment">// obj.name     : key data</span></div>
<div class="line">   <span class="comment">// obj.namesize : key size</span></div>
<div class="line">   <span class="comment">// obj.data     : data</span></div>
<div class="line">   <span class="comment">// obj.datasize : data size</span></div>
<div class="line">   <span class="comment">//</span></div>
<div class="line">   <span class="comment">// Do free obj.name and obj.data if newmem is set to true;</span></div>
<div class="line">}</div>
<div class="line">tbl-&gt;unlock(tbl);</div>
</div><!-- fragment --><div class="fragment"><div class="line">[Iteration example from given point]</div>
<div class="line"></div>
<div class="line">qtreetbl_obj_t obj;</div>
<div class="line">memset((<span class="keywordtype">void</span>*)&amp;obj, 0, <span class="keyword">sizeof</span>(obj));</div>
<div class="line">tbl-&gt;lock(tbl);  <span class="comment">// lock must be raised before find_nearest() call.</span></div>
<div class="line">qtreetbl_obj_t obj = tbl-&gt;find_nearest(tbl, <span class="stringliteral">&quot;F&quot;</span>, 2, <span class="keyword">false</span>); <span class="comment">// here we go!</span></div>
<div class="line"><span class="keywordflow">while</span> (tbl-&gt;getnext(tbl, &amp;obj, <span class="keyword">false</span>) == <span class="keyword">true</span>) {  <span class="comment">// newmem is false</span></div>
<div class="line">    <span class="comment">//If tree has 5 objects, A, C, E, G and I.</span></div>
<div class="line">    <span class="comment">//Iteration sequence from nearest &quot;F&quot; will be: E-&gt;G-&gt;I-&gt;A-&gt;C</span></div>
<div class="line">}</div>
<div class="line">tbl-&gt;unlock(tbl);</div>
</div><!-- fragment --><div class="fragment"><div class="line">[Removal example in iteration loop]</div>
<div class="line">  qtreetbl_obj_t obj;</div>
<div class="line">  memset((<span class="keywordtype">void</span>*) &amp;obj, 0, <span class="keyword">sizeof</span>(obj));  <span class="comment">// start from the minimum.</span></div>
<div class="line">  tbl-&gt;lock(tbl);</div>
<div class="line">  <span class="keywordflow">while</span> (tbl-&gt;getnext(tbl, &amp;obj, <span class="keyword">false</span>) == <span class="keyword">true</span>) {</div>
<div class="line">      <span class="keywordflow">if</span> (...condition...) {</div>
<div class="line">          <span class="keywordtype">char</span> *name = <a class="code" href="qstring_8c.html#acc32dbf9f419ef637d0547211b7125b9">qmemdup</a>(obj.name, obj.namesize);  <span class="comment">// keep the name</span></div>
<div class="line">          <span class="keywordtype">size_t</span> namesize = obj.namesize;                <span class="comment">// for removal argument</span></div>
<div class="line"></div>
<div class="line">          tbl-&gt;remove_by_obj(tbl, obj.name, obj.namesize);  <span class="comment">// remove</span></div>
<div class="line"></div>
<div class="line">          obj = tbl-&gt;find_nearest(tbl, name, namesize, <span class="keyword">false</span>); <span class="comment">// rewind one step back</span></div>
<div class="line"></div>
<div class="line">          free(name);  <span class="comment">// clean up</span></div>
<div class="line">      }</div>
<div class="line">  }</div>
<div class="line">  tbl-&gt;unlock(tbl);</div>
</div><!-- fragment --><dl class="section note"><dt>Note</dt><dd><ul>
<li>locking must be provided on user code when thread condition is expected because entire traversal needs to be running under read-only mode.</li>
<li>Data insertion or deletion can be made during the traversal, but in that case iterator doesn't guarantee full sweep and possibly skip some visits. When deletion happens in getnext() loop, use find_nearest() to rewind the iterator one step back.</li>
<li>Object obj should be initialized with 0 by using memset() before first call.</li>
<li>If newmem flag is true, user should de-allocate obj.name and obj.data resources. </li>
</ul>
</dd></dl>

<p>Definition at line <a class="el" href="qtreetbl_8c_source.html#l00578">578</a> of file <a class="el" href="qtreetbl_8c_source.html">qtreetbl.c</a>.</p>

</div>
</div>
<a class="anchor" id="a1f037a026ec877becd4f010226e00ea4"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void* qtreetbl_find_min </td>
          <td>(</td>
          <td class="paramtype">qtreetbl_t *&#160;</td>
          <td class="paramname"><em>tbl</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t *&#160;</td>
          <td class="paramname"><em>namesize</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>qtreetbl-&gt;find_min(): Find the name of very left object. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">tbl</td><td>qtreetbl_t container pointer. </td></tr>
    <tr><td class="paramname">namesize</td><td>if not NULL, the size of key name will be stored.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>malloced memory copying the key name.</dd></dl>
<dl class="section note"><dt>Note</dt><dd>It's user's responsibility to free the return. </dd></dl>

<p>Definition at line <a class="el" href="qtreetbl_8c_source.html#l00632">632</a> of file <a class="el" href="qtreetbl_8c_source.html">qtreetbl.c</a>.</p>

</div>
</div>
<a class="anchor" id="a1f70611ea89775d0ec580cc13eaa0069"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void* qtreetbl_find_max </td>
          <td>(</td>
          <td class="paramtype">qtreetbl_t *&#160;</td>
          <td class="paramname"><em>tbl</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t *&#160;</td>
          <td class="paramname"><em>namesize</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>qtreetbl-&gt;find_max(): Find the name of very right object. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">tbl</td><td>qtreetbl_t container pointer. </td></tr>
    <tr><td class="paramname">namesize</td><td>if not NULL, the size of key name will be stored.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>malloced memory copying the key name.</dd></dl>
<dl class="section note"><dt>Note</dt><dd>It's user's responsibility to free the return. </dd></dl>

<p>Definition at line <a class="el" href="qtreetbl_8c_source.html#l00660">660</a> of file <a class="el" href="qtreetbl_8c_source.html">qtreetbl.c</a>.</p>

</div>
</div>
<a class="anchor" id="aa2c4f3ac4623feb251fadabbdf734bdd"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">qtreetbl_obj_t qtreetbl_find_nearest </td>
          <td>(</td>
          <td class="paramtype">qtreetbl_t *&#160;</td>
          <td class="paramname"><em>tbl</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const void *&#160;</td>
          <td class="paramname"><em>name</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t&#160;</td>
          <td class="paramname"><em>namesize</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool&#160;</td>
          <td class="paramname"><em>newmem</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>qtreetbl-&gt;find_nearest(): Find equal or nearest object. </p>
<p>find_nearest() returns matching key or nearest key. If there's no keys in the table. It'll return empty qtreetbl_obj_t object with errno ENOENT.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">tbl</td><td>qtreetbl_t container pointer. </td></tr>
    <tr><td class="paramname">name</td><td>key name </td></tr>
    <tr><td class="paramname">namesize</td><td>key size </td></tr>
    <tr><td class="paramname">newmem</td><td>whether or not to allocate memory for the data.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>qtreetbl_obj_t object.</dd></dl>
<dl class="retval"><dt>Return values</dt><dd>
  <table class="retval">
    <tr><td class="paramname">errno</td><td>will be set in error condition.<ul>
<li>ENOENT : No next element.</li>
<li>EINVAL : Invalid argument.</li>
<li>ENOMEM : Memory allocation failure.</li>
</ul>
</td></tr>
  </table>
  </dd>
</dl>
<div class="fragment"><div class="line">[Some examples here]</div>
<div class="line">Data Set : A B C D E I N R S X</div>
<div class="line">find_nearest(<span class="stringliteral">&quot;0&quot;</span>) =&gt; <span class="stringliteral">&quot;A&quot;</span> <span class="comment">// no smaller key available, so &quot;A&quot;</span></div>
<div class="line">find_nearest(<span class="stringliteral">&quot;C&quot;</span>) =&gt; <span class="stringliteral">&quot;C&quot;</span> <span class="comment">// matching key found</span></div>
<div class="line">find_nearest(<span class="stringliteral">&quot;F&quot;</span>) =&gt; <span class="stringliteral">&quot;E&quot;</span> <span class="comment">// &quot;E&quot; is nearest smaller key from &quot;F&quot;</span></div>
<div class="line">find_nearest(<span class="stringliteral">&quot;M&quot;</span>) =&gt; <span class="stringliteral">&quot;N&quot;</span> <span class="comment">// &quot;N&quot; is nearest smaller key from &quot;M&quot;</span></div>
<div class="line">find_nearest(<span class="stringliteral">&quot;Z&quot;</span>) =&gt; <span class="stringliteral">&quot;X&quot;</span> <span class="comment">// &quot;X&quot; is nearest smaller key from &quot;Z&quot;</span></div>
</div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>When there's no matching key it look for closest smaller key in the neighbors. The only exception when it returns bigger key than given search key is that when there's no smaller keys available in the table. In such case, it'll return the nearest bigger key. </dd></dl>

<p>Definition at line <a class="el" href="qtreetbl_8c_source.html#l00712">712</a> of file <a class="el" href="qtreetbl_8c_source.html">qtreetbl.c</a>.</p>

</div>
</div>
<a class="anchor" id="a3537212a86616d50459eec229d94f8e4"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">size_t qtreetbl_size </td>
          <td>(</td>
          <td class="paramtype">qtreetbl_t *&#160;</td>
          <td class="paramname"><em>tbl</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>qtreetbl-&gt;size(): Returns the number of keys in the table. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">tbl</td><td>qtreetbl_t container pointer.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>number of elements stored </dd></dl>

<p>Definition at line <a class="el" href="qtreetbl_8c_source.html#l00777">777</a> of file <a class="el" href="qtreetbl_8c_source.html">qtreetbl.c</a>.</p>

</div>
</div>
<a class="anchor" id="a7b324cf9e317a2623c5767b8a0183f72"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void qtreetbl_clear </td>
          <td>(</td>
          <td class="paramtype">qtreetbl_t *&#160;</td>
          <td class="paramname"><em>tbl</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>qtreetbl-&gt;clear(): Clears the table so that it contains no keys. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">tbl</td><td>qtreetbl_t container pointer. </td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="qtreetbl_8c_source.html#l00786">786</a> of file <a class="el" href="qtreetbl_8c_source.html">qtreetbl.c</a>.</p>

</div>
</div>
<a class="anchor" id="a5c8aa458bac0dc5e7dc0ab97c6f52dfd"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void qtreetbl_lock </td>
          <td>(</td>
          <td class="paramtype">qtreetbl_t *&#160;</td>
          <td class="paramname"><em>tbl</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>qtreetbl-&gt;lock(): Enter critical section. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">tbl</td><td>qtreetbl_t container pointer.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section note"><dt>Note</dt><dd>From user side, normally locking operation is only needed when traverse all elements using qtreetbl-&gt;getnext().</dd>
<dd>
This operation will do nothing if QTREETBL_THREADSAFE option was not given at the initialization time. </dd></dl>

<p>Definition at line <a class="el" href="qtreetbl_8c_source.html#l00807">807</a> of file <a class="el" href="qtreetbl_8c_source.html">qtreetbl.c</a>.</p>

</div>
</div>
<a class="anchor" id="a88a8e67f478390c6b25780fda3134a8d"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void qtreetbl_unlock </td>
          <td>(</td>
          <td class="paramtype">qtreetbl_t *&#160;</td>
          <td class="paramname"><em>tbl</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>qtreetbl-&gt;unlock(): Leave critical section. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">tbl</td><td>qtreetbl_t container pointer.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section note"><dt>Note</dt><dd>This operation will do nothing if QTREETBL_THREADSAFE option was not given at the initialization time. </dd></dl>

<p>Definition at line <a class="el" href="qtreetbl_8c_source.html#l00820">820</a> of file <a class="el" href="qtreetbl_8c_source.html">qtreetbl.c</a>.</p>

</div>
</div>
<a class="anchor" id="a2bac240b706b85273338a26fb986eee7"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void qtreetbl_free </td>
          <td>(</td>
          <td class="paramtype">qtreetbl_t *&#160;</td>
          <td class="paramname"><em>tbl</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>qtreetbl-&gt;free(): De-allocate the table </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">tbl</td><td>qtreetbl_t container pointer. </td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="qtreetbl_8c_source.html#l00829">829</a> of file <a class="el" href="qtreetbl_8c_source.html">qtreetbl.c</a>.</p>

</div>
</div>
<a class="anchor" id="a663dfe23addb8debd1c3da5e54d2c930"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool qtreetbl_debug </td>
          <td>(</td>
          <td class="paramtype">qtreetbl_t *&#160;</td>
          <td class="paramname"><em>tbl</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">FILE *&#160;</td>
          <td class="paramname"><em>out</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>qtreetbl-&gt;debug(): Print hash table for debugging purpose </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">tbl</td><td>qtreetbl_t container pointer. </td></tr>
    <tr><td class="paramname">out</td><td>output stream</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>true if successful, otherwise returns false. </dd></dl>
<dl class="retval"><dt>Return values</dt><dd>
  <table class="retval">
    <tr><td class="paramname">errno</td><td>will be set in error condition.<ul>
<li>EIO : Invalid output stream. </li>
</ul>
</td></tr>
  </table>
  </dd>
</dl>

<p>Definition at line <a class="el" href="qtreetbl_8c_source.html#l00854">854</a> of file <a class="el" href="qtreetbl_8c_source.html">qtreetbl.c</a>.</p>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_0b61c55142250c0cc363383afd8075a4.html">containers</a></li><li class="navelem"><a class="el" href="qtreetbl_8c.html">qtreetbl.c</a></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.6 </li>
  </ul>
</div>
</body>
</html>
